package com.rock.code.bigdata.forecast.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.rock.code.base.service.impl.BaseServiceImpl;
import com.rock.code.bigdata.forecast.dao.ForecastDao;
import com.rock.code.bigdata.forecast.domain.TbSysForeCast;
import com.rock.code.bigdata.forecast.service.ForeCastService;
import com.rock.code.bigdata.targets.dao.TbSysTargetDao;
import com.rock.code.bigdata.targets.domain.TbSysTarget;
import com.rock.code.common.pager.Page;
import org.apache.poi.hssf.record.formula.functions.T;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ForceCastServiceImpl extends BaseServiceImpl<ForecastDao> implements ForeCastService {

    @Resource
    private ForecastDao forecastDao;


    @Override
    public List queryData(Map<String, Object> param) {
        return null;
    }

    @Override
    public PageInfo queryPageListForceCast(Page page, Map<String, Object> param) throws Exception {
        String orderBy = "";
        if (!StringUtil.isEmpty(page.getSidx())) {
            orderBy = this.getOrderBy(page);
        }
        PageHelper.startPage(page.getPage(), page.getRows());
        if (!orderBy.equals("")) {
            PageHelper.orderBy(orderBy);
        }
        List<TbSysForeCast> list = forecastDao.queryPageListForceCast(param);
        return new PageInfo(list);
    }

    @Override
    public int insert(Object o) throws Exception {
        return 0;
    }

    @Override
    public int delete(String primaryKey) throws Exception {
        return 0;
    }

    @Override
    public int update(Object o) throws Exception {
        return 0;
    }

    @Override
    public Object query(Object o) throws Exception {
        return null;
    }

    @Override
    public List queryList(Object o) throws Exception {
        return null;
    }

    @Override
    public List queryListByOrder(Page page, Map param) throws Exception {
        return null;
    }

    @Override
    public PageInfo queryPageList(Page page, Map param) throws Exception {
        return null;
    }

    @Override
    public List queryListByParaMap(Map param) throws Exception {
        return null;
    }

    @Override
    public Object queryByParaMap(Map param) throws Exception {
        return null;
    }

    @Override
    public int deleteByParam(Map param) throws Exception {
        return 0;
    }


    //=========================================================================================================

    @Override
    public List forecastQuery(Map map) {
        return forecastDao.forecastQuery(map);
    }

    @Override
    public String monthTableName() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, 0);
        String monthtable = new SimpleDateFormat("yyyyMM").format(cal.getTime());
        return "tb_kpitrend_value_day_" + monthtable;
    }

    @Override
    public String forecastDate() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, 0);
        cal.add(Calendar.DATE, 0);
        String forecastDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        return forecastDate;
    }

    @Override
    public List queryDrz(Map map) {
        return forecastDao.queryDrz(map);
    }

    @Override
    public String thevalueofDate() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, 0);
        cal.add(Calendar.DATE, 0);
        String thevalueofDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        return thevalueofDate;
    }

    @Override
    public List queryJx(Map map) {
        return forecastDao.queryJx(map);
    }

    @Override
    public String monthTableNameJx() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, 0);
        cal.add(Calendar.DATE, -1);
        String monthtableJx = new SimpleDateFormat("yyyyMM").format(cal.getTime());
        return "tb_kpibaseline_value_" + monthtableJx;
    }

    @Override
    public String baseLineDate() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, 0);
        cal.add(Calendar.DATE, -1);
        String baseLineDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        return baseLineDate;
    }

    @Override
    public List FileSystem(Map map) {
        return forecastDao.FileSystem(map);
    }

    @Override
    public List FileSystemJx(Map map) {
        return forecastDao.FileSystemJx(map);
    }

    @Override
    public List FileSystemDrz(Map map) {
        return forecastDao.FileSystemDrz(map);
    }
}
